﻿namespace WMS6.SQLServerDAL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;

    public class PurchaseOrderDetailDA : IPurchaseOrderDetailDA
    {
        private string ADJUSTED_QTY = "@ADJUSTED_QTY";
        private string ALT_SKU_ID = "@ALT_SKU_ID";
        private string CREATED_BY = "@CREATED_BY";
        private string EXTERNAL_LINE_ID = "@EXTERNAL_LINE_ID";
        private string EXTERNAL_PO_ID = "@EXTERNAL_PO_ID";
        private string LINE_ID = "@LINE_ID";
        private string ORDERED_QTY = "@ORDERED_QTY";
        private string OWNER_ID = "@OWNER_ID";
        private string PACK_ID = "@PACK_ID";
        private string PO_ID = "@PO_ID";
        private string QC_AUTO_ADJUST = "@QC_AUTO_ADJUST";
        private string QC_REQUIRED = "@QC_REQUIRED";
        private string RECEIVED_QTY = "@RECEIVED_QTY";
        private string REJECTED_QTY = "@REJECTED_QTY";
        private string REMARK = "@REMARK";
        private string SKU_DESC = "@SKU_DESC";
        private string SKU_ID = "@SKU_ID";
        private string SQL_CHECK_PURCHASE_ORDER_DETAIL_ID_UNIQUE = " SELECT COUNT(1) FROM @_@PURCHASE_ORDER_DETAIL WHERE PO_ID = @PO_ID AND LINE_ID = @LINE_ID ";
        private string SQL_DELETE_PURCHASE_ORDER_DETAIL = " DELETE FROM @_@PURCHASE_ORDER_DETAIL WHERE  ";
        private string SQL_INSERT_PURCHASE_ORDER_DETAIL = " INSERT INTO @_@PURCHASE_ORDER_DETAIL ( WH_ID, PO_ID, LINE_ID, OWNER_ID, EXTERNAL_PO_ID, EXTERNAL_LINE_ID, STATUS, SKU_ID, SKU_DESC, ALT_SKU_ID, ORDERED_QTY, ADJUSTED_QTY, RECEIVED_QTY, REJECTED_QTY, PACK_ID, UNIT_PRICE, UOM_ID, TOTAL_GROSS_WEIGHT, TOTAL_NET_WEIGHT, TOTAL_CUBE, TOTAL_PRICE, QC_AUTO_ADJUST, QC_REQUIRED, UDF1, UDF2, UDF3, UDF4, UDF5, UDF6, UDF7, UDF8, UDF9, UDF10, REMARK, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE) VALUES ( @WH_ID, @PO_ID, @LINE_ID, @OWNER_ID, @EXTERNAL_PO_ID, @EXTERNAL_LINE_ID, @STATUS, @SKU_ID, @SKU_DESC, @ALT_SKU_ID, @ORDERED_QTY, @ADJUSTED_QTY, @RECEIVED_QTY, @REJECTED_QTY, @PACK_ID, @UNIT_PRICE, @UOM_ID, @TOTAL_GROSS_WEIGHT, @TOTAL_NET_WEIGHT, @TOTAL_CUBE, @TOTAL_PRICE, @QC_AUTO_ADJUST, @QC_REQUIRED, @UDF1, @UDF2, @UDF3, @UDF4, @UDF5, @UDF6, @UDF7, @UDF8, @UDF9, @UDF10, @REMARK, @CREATED_BY, GETDATE(), @UPDATED_BY, GETDATE() )  ";
        private string SQL_SELECT_ALL_PURCHASE_ORDER_DETAIL = " SELECT  POD.ROWID, POD.WH_ID, POD.PO_ID, POD.LINE_ID, POD.OWNER_ID, POD.EXTERNAL_PO_ID, POD.EXTERNAL_LINE_ID, POD.STATUS,T.[TEXT] AS STATUS_D, POD.SKU_ID, POD.SKU_DESC,POD.ALT_SKU_ID,POD.ORDERED_QTY, POD.ADJUSTED_QTY, POD.RECEIVED_QTY, POD.REJECTED_QTY, POD.PACK_ID, POD.UNIT_PRICE, POD.UOM_ID, POD.TOTAL_GROSS_WEIGHT, POD.TOTAL_NET_WEIGHT, POD.TOTAL_CUBE, POD.TOTAL_PRICE, POD.QC_AUTO_ADJUST, POD.QC_REQUIRED, POD.UDF1, POD.UDF2, POD.UDF3, POD.UDF4, POD.UDF5, POD.UDF6, POD.UDF7, POD.UDF8, POD.UDF9, POD.UDF10, POD.REMARK, POD.TS, POD.CREATED_BY, POD.CREATED_DATE, POD.UPDATED_BY, POD.UPDATED_DATE   FROM  @_@PURCHASE_ORDER_DETAIL POD LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE = POD.STATUS AND SCD.SYS_CODE_TYPE = 'PoStatus' LEFT JOIN sysadm.TRANSLATION T ON 'PoStatus.'+POD.STATUS = T.ITEM_ID  \t\t\tAND  T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE INNER JOIN SYSADM.USER_OWNER UO ON POD.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID ";
        private string SQL_UPDATE_PURCHASE_ORDER_DETAIL = " UPDATE @_@PURCHASE_ORDER_DETAIL SET WH_ID = @WH_ID, OWNER_ID = @OWNER_ID, EXTERNAL_PO_ID = @EXTERNAL_PO_ID, EXTERNAL_LINE_ID = @EXTERNAL_LINE_ID, STATUS = @STATUS, SKU_ID = @SKU_ID, SKU_DESC = @SKU_DESC, ALT_SKU_ID = @ALT_SKU_ID, ORDERED_QTY = @ORDERED_QTY, ADJUSTED_QTY = @ADJUSTED_QTY, RECEIVED_QTY = @RECEIVED_QTY, REJECTED_QTY = @REJECTED_QTY, PACK_ID = @PACK_ID, UNIT_PRICE = @UNIT_PRICE, UOM_ID = @UOM_ID, TOTAL_GROSS_WEIGHT = @TOTAL_GROSS_WEIGHT, TOTAL_NET_WEIGHT = @TOTAL_NET_WEIGHT, TOTAL_CUBE = @TOTAL_CUBE, TOTAL_PRICE = @TOTAL_PRICE, QC_AUTO_ADJUST = @QC_AUTO_ADJUST, QC_REQUIRED = @QC_REQUIRED, UDF1 = @UDF1, UDF2 = @UDF2, UDF3 = @UDF3, UDF4 = @UDF4, UDF5 = @UDF5, UDF6 = @UDF6, UDF7 = @UDF7, UDF8 = @UDF8, UDF9 = @UDF9, UDF10 = @UDF10, REMARK = @REMARK, UPDATED_BY = @UPDATED_BY, UPDATED_DATE = GETDATE() WHERE PO_ID = @PO_ID AND LINE_ID = @LINE_ID  ";
        private string SQL_UPDATE_PURCHASE_ORDER_DETAIL_PRICE = " UPDATE @_@PURCHASE_ORDER_DETAIL SET UNIT_PRICE = @UNIT_PRICE, UPDATED_BY = @UPDATED_BY, UPDATED_DATE = GETDATE() WHERE PO_ID = @PO_ID AND LINE_ID=@LINE_ID ";
        private string SQL_UPDATE_PURCHASE_ORDER_DETAIL_STAUTS = " UPDATE @_@PURCHASE_ORDER_DETAIL SET STATUS = @STATUS, UPDATED_BY = @UPDATED_BY, UPDATED_DATE = GETDATE() WHERE PO_ID = @PO_ID ";
        private string STATUS = "@STATUS";
        private string TOTAL_CUBE = "@TOTAL_CUBE";
        private string TOTAL_GROSS_WEIGHT = "@TOTAL_GROSS_WEIGHT";
        private string TOTAL_NET_WEIGHT = "@TOTAL_NET_WEIGHT";
        private string TOTAL_PRICE = "@TOTAL_PRICE";
        private string TS = "@TS";
        private string UDF1 = "@UDF1";
        private string UDF10 = "@UDF10";
        private string UDF2 = "@UDF2";
        private string UDF3 = "@UDF3";
        private string UDF4 = "@UDF4";
        private string UDF5 = "@UDF5";
        private string UDF6 = "@UDF6";
        private string UDF7 = "@UDF7";
        private string UDF8 = "@UDF8";
        private string UDF9 = "@UDF9";
        private string UNIT_PRICE = "@UNIT_PRICE";
        private string UOM_ID = "@UOM_ID";
        private string UPDATED_BY = "@UPDATED_BY";
        private string WH_ID = "@WH_ID";

        public bool CheckPurchaseOrderDetailIDUnique(string poID, string lineID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@PO_ID", poID), new SqlParameter("@LINE_ID", lineID) };
            return (DBHelper.ExecuteScalar(CommandType.Text, this.SQL_CHECK_PURCHASE_ORDER_DETAIL_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public bool CheckPurchaseOrderDetailIDUnique(DataBase dataBase, DbTransaction tran, string poID, string lineID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@PO_ID", poID), new SqlParameter("@LINE_ID", lineID) };
            return (dataBase.ExecuteScalar(tran, CommandType.Text, this.SQL_CHECK_PURCHASE_ORDER_DETAIL_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public int DeletePurchaseOrderDetail(List<string> poID, List<string> whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    string sql = this.SQL_DELETE_PURCHASE_ORDER_DETAIL.Replace("@_@", whLoginID[i]) + " PO_ID = @PO_ID ";
                    for (int j = 0; j < poID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@PO_ID", poID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, sql, paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeletePurchaseOrderDetail(List<string> poID, List<string> lineID, List<string> whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    string sql = this.SQL_DELETE_PURCHASE_ORDER_DETAIL.Replace("@_@", whLoginID[i]) + " PO_ID = @PO_ID AND LINE_ID = @LINE_ID ";
                    for (int j = 0; j < poID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@PO_ID", poID[j]), new SqlParameter("@LINE_ID", lineID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, sql, paras);
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeletePurchaseOrderDetail(DataBase dataBase, DbTransaction tran, List<string> poID, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < poID.Count; j++)
                    {
                        string sql = this.SQL_DELETE_PURCHASE_ORDER_DETAIL.Replace("@_@", whLoginID[i]) + "  PO_ID = @PO_ID ";
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@PO_ID", poID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, sql, paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int DeletePurchaseOrderDetail(DataBase dataBase, DbTransaction tran, List<string> poID, List<string> lineID, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < poID.Count; j++)
                    {
                        string sql = this.SQL_DELETE_PURCHASE_ORDER_DETAIL.Replace("@_@", whLoginID[i]) + "  PO_ID = @PO_ID AND LINE_ID = @LINE_ID ";
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@PO_ID", poID[j]), new SqlParameter("@LINE_ID", lineID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, sql, paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public DataSet GetAllPurchaseOrderDetail(string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_PURCHASE_ORDER_DETAIL.Replace("@_@", whLoginID);
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage), new SqlParameter("@USER_ID", pubParasInfo.UserID) };
            return DBHelper.ExecuteDataSet(CommandType.Text, sql, paras);
        }

        public DataSet GetAllPurchaseOrderDetail(DataBase dataBase, DbTransaction tran, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_PURCHASE_ORDER_DETAIL.Replace("@_@", whLoginID);
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage), new SqlParameter("@USER_ID", pubParasInfo.UserID) };
            return dataBase.ExecuteDataSet(tran, CommandType.Text, sql, paras);
        }

        public PurchaseOrderDetailInfo GetPurchaseOrderDetailByID(string poID, string lineID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_PURCHASE_ORDER_DETAIL.Replace("@_@", whLoginID) + " WHERE POD.PO_ID = @PO_ID AND POD.LINE_ID = @LINE_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@PO_ID", poID), new SqlParameter("@LINE_ID", lineID), new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage), new SqlParameter("@USER_ID", pubParasInfo.UserID) };
            PurchaseOrderDetailInfo purchaseOrderDetailInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                if (reader.Read())
                {
                    purchaseOrderDetailInfo = new PurchaseOrderDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["PO_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, reader["OWNER_ID"].ToString(), reader["EXTERNAL_PO_ID"].ToString(), reader["EXTERNAL_LINE_ID"].ToString(), reader["STATUS"].ToString(), reader["SKU_ID"].ToString(), reader["SKU_DESC"].ToString(), reader["ALT_SKU_ID"].ToString(), (reader["ORDERED_QTY"].ToString() != "") ? decimal.Parse(reader["ORDERED_QTY"].ToString()) : 0M, (reader["ADJUSTED_QTY"].ToString() != "") ? decimal.Parse(reader["ADJUSTED_QTY"].ToString()) : 0M, (reader["RECEIVED_QTY"].ToString() != "") ? decimal.Parse(reader["RECEIVED_QTY"].ToString()) : 0M, (reader["REJECTED_QTY"].ToString() != "") ? decimal.Parse(reader["REJECTED_QTY"].ToString()) : 0M, reader["PACK_ID"].ToString(), (reader["UNIT_PRICE"].ToString() != "") ? ((double) float.Parse(reader["UNIT_PRICE"].ToString())) : ((double) 0f), reader["UOM_ID"].ToString(), (reader["TOTAL_GROSS_WEIGHT"].ToString() != "") ? ((double) float.Parse(reader["TOTAL_GROSS_WEIGHT"].ToString())) : ((double) 0f), (reader["TOTAL_NET_WEIGHT"].ToString() != "") ? ((double) float.Parse(reader["TOTAL_NET_WEIGHT"].ToString())) : ((double) 0f), (reader["TOTAL_CUBE"].ToString() != "") ? ((double) float.Parse(reader["TOTAL_CUBE"].ToString())) : ((double) 0f), (reader["TOTAL_PRICE"].ToString() != "") ? ((double) float.Parse(reader["TOTAL_PRICE"].ToString())) : ((double) 0f), reader["QC_AUTO_ADJUST"].ToString(), reader["QC_REQUIRED"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["REMARK"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime(), reader["STATUS_D"].ToString());
                }
            }
            return purchaseOrderDetailInfo;
        }

        public PurchaseOrderDetailInfo GetPurchaseOrderDetailByID(DataBase dataBase, DbTransaction tran, string poID, string lineID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_PURCHASE_ORDER_DETAIL.Replace("@_@", whLoginID) + " WHERE POD.PO_ID = @PO_ID AND POD.LINE_ID = @LINE_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@PO_ID", poID), new SqlParameter("@LINE_ID", lineID), new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage), new SqlParameter("@USER_ID", pubParasInfo.UserID) };
            PurchaseOrderDetailInfo purchaseOrderDetailInfo = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            if (reader.Read())
            {
                purchaseOrderDetailInfo = new PurchaseOrderDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["PO_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, reader["OWNER_ID"].ToString(), reader["EXTERNAL_PO_ID"].ToString(), reader["EXTERNAL_LINE_ID"].ToString(), reader["STATUS"].ToString(), reader["SKU_ID"].ToString(), reader["SKU_DESC"].ToString(), reader["ALT_SKU_ID"].ToString(), (reader["ORDERED_QTY"].ToString() != "") ? decimal.Parse(reader["ORDERED_QTY"].ToString()) : 0M, (reader["ADJUSTED_QTY"].ToString() != "") ? decimal.Parse(reader["ADJUSTED_QTY"].ToString()) : 0M, (reader["RECEIVED_QTY"].ToString() != "") ? decimal.Parse(reader["RECEIVED_QTY"].ToString()) : 0M, (reader["REJECTED_QTY"].ToString() != "") ? decimal.Parse(reader["REJECTED_QTY"].ToString()) : 0M, reader["PACK_ID"].ToString(), (reader["UNIT_PRICE"].ToString() != "") ? ((double) float.Parse(reader["UNIT_PRICE"].ToString())) : ((double) 0f), reader["UOM_ID"].ToString(), (reader["TOTAL_GROSS_WEIGHT"].ToString() != "") ? ((double) float.Parse(reader["TOTAL_GROSS_WEIGHT"].ToString())) : ((double) 0f), (reader["TOTAL_NET_WEIGHT"].ToString() != "") ? ((double) float.Parse(reader["TOTAL_NET_WEIGHT"].ToString())) : ((double) 0f), (reader["TOTAL_CUBE"].ToString() != "") ? ((double) float.Parse(reader["TOTAL_CUBE"].ToString())) : ((double) 0f), (reader["TOTAL_PRICE"].ToString() != "") ? ((double) float.Parse(reader["TOTAL_PRICE"].ToString())) : ((double) 0f), reader["QC_AUTO_ADJUST"].ToString(), reader["QC_REQUIRED"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["REMARK"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime(), reader["STATUS_D"].ToString());
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return purchaseOrderDetailInfo;
        }

        public DataSet GetPurchaseOrderDetailByQueryList(List<string> sqlWhere, PurchaseOrderDetailQueryEntity purchaseorderdetailQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string temp = this.SQL_SELECT_ALL_PURCHASE_ORDER_DETAIL.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!purchaseorderdetailQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, purchaseorderdetailQuery.CurrentPage, purchaseorderdetailQuery.PageSize, purchaseorderdetailQuery.SortField, purchaseorderdetailQuery.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                temp = temp.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'");
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, temp);
        }

        public DataSet GetPurchaseOrderDetailByQueryList(DataBase dataBase, DbTransaction tran, List<string> sqlWhere, PurchaseOrderDetailQueryEntity purchaseorderdetailQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string temp = this.SQL_SELECT_ALL_PURCHASE_ORDER_DETAIL.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!purchaseorderdetailQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, purchaseorderdetailQuery.CurrentPage, purchaseorderdetailQuery.PageSize, purchaseorderdetailQuery.SortField, purchaseorderdetailQuery.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                temp = temp.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'");
            }
            return dataBase.ExecuteDataSet(tran, CommandType.Text, temp);
        }

        public List<PurchaseOrderDetailInfo> GetPurchaseOrderDetailListByID(string poID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sqlStr = this.SQL_SELECT_ALL_PURCHASE_ORDER_DETAIL.Replace("@_@", whLoginID) + "  WHERE POD.PO_ID = @PO_ID ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@PO_ID", poID), new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage), new SqlParameter("@USER_ID", pubParasInfo.UserID) };
            List<PurchaseOrderDetailInfo> purchaseOrderDetailInfos = new List<PurchaseOrderDetailInfo>();
            PurchaseOrderDetailInfo purchaseOrderDetailInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sqlStr, paras))
            {
                while (reader.Read())
                {
                    DateTime CS00002;
                    purchaseOrderDetailInfo = new PurchaseOrderDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["PO_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, reader["OWNER_ID"].ToString(), reader["EXTERNAL_PO_ID"].ToString(), reader["EXTERNAL_LINE_ID"].ToString(), reader["STATUS"].ToString(), reader["SKU_ID"].ToString(), reader["SKU_DESC"].ToString(), reader["ALT_SKU_ID"].ToString(), (reader["ORDERED_QTY"].ToString() != "") ? decimal.Parse(reader["ORDERED_QTY"].ToString()) : 0M, (reader["ADJUSTED_QTY"].ToString() != "") ? decimal.Parse(reader["ADJUSTED_QTY"].ToString()) : 0M, (reader["RECEIVED_QTY"].ToString() != "") ? decimal.Parse(reader["RECEIVED_QTY"].ToString()) : 0M, (reader["REJECTED_QTY"].ToString() != "") ? decimal.Parse(reader["REJECTED_QTY"].ToString()) : 0M, reader["PACK_ID"].ToString(), (reader["UNIT_PRICE"].ToString() != "") ? ((double) float.Parse(reader["UNIT_PRICE"].ToString())) : ((double) 0f), reader["UOM_ID"].ToString(), (reader["TOTAL_GROSS_WEIGHT"].ToString() != "") ? ((double) float.Parse(reader["TOTAL_GROSS_WEIGHT"].ToString())) : ((double) 0f), (reader["TOTAL_NET_WEIGHT"].ToString() != "") ? ((double) float.Parse(reader["TOTAL_NET_WEIGHT"].ToString())) : ((double) 0f), (reader["TOTAL_CUBE"].ToString() != "") ? ((double) float.Parse(reader["TOTAL_CUBE"].ToString())) : ((double) 0f), (reader["TOTAL_PRICE"].ToString() != "") ? ((double) float.Parse(reader["TOTAL_PRICE"].ToString())) : ((double) 0f), reader["QC_AUTO_ADJUST"].ToString(), reader["QC_REQUIRED"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["REMARK"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["STATUS_D"].ToString());
                    purchaseOrderDetailInfos.Add(purchaseOrderDetailInfo);
                }
            }
            return purchaseOrderDetailInfos;
        }

        public List<PurchaseOrderDetailInfo> GetPurchaseOrderDetailListByID(DataBase dataBase, DbTransaction tran, string poID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sqlStr = this.SQL_SELECT_ALL_PURCHASE_ORDER_DETAIL.Replace("@_@", whLoginID) + "  WHERE POD.PO_ID = @PO_ID ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@PO_ID", poID), new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage), new SqlParameter("@USER_ID", pubParasInfo.UserID) };
            List<PurchaseOrderDetailInfo> purchaseOrderDetailInfos = new List<PurchaseOrderDetailInfo>();
            PurchaseOrderDetailInfo purchaseOrderDetailInfo = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sqlStr, paras);
            while (reader.Read())
            {
                DateTime CS00002;
                purchaseOrderDetailInfo = new PurchaseOrderDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["PO_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, reader["OWNER_ID"].ToString(), reader["EXTERNAL_PO_ID"].ToString(), reader["EXTERNAL_LINE_ID"].ToString(), reader["STATUS"].ToString(), reader["SKU_ID"].ToString(), reader["SKU_DESC"].ToString(), reader["ALT_SKU_ID"].ToString(), (reader["ORDERED_QTY"].ToString() != "") ? decimal.Parse(reader["ORDERED_QTY"].ToString()) : 0M, (reader["ADJUSTED_QTY"].ToString() != "") ? decimal.Parse(reader["ADJUSTED_QTY"].ToString()) : 0M, (reader["RECEIVED_QTY"].ToString() != "") ? decimal.Parse(reader["RECEIVED_QTY"].ToString()) : 0M, (reader["REJECTED_QTY"].ToString() != "") ? decimal.Parse(reader["REJECTED_QTY"].ToString()) : 0M, reader["PACK_ID"].ToString(), (reader["UNIT_PRICE"].ToString() != "") ? ((double) float.Parse(reader["UNIT_PRICE"].ToString())) : ((double) 0f), reader["UOM_ID"].ToString(), (reader["TOTAL_GROSS_WEIGHT"].ToString() != "") ? ((double) float.Parse(reader["TOTAL_GROSS_WEIGHT"].ToString())) : ((double) 0f), (reader["TOTAL_NET_WEIGHT"].ToString() != "") ? ((double) float.Parse(reader["TOTAL_NET_WEIGHT"].ToString())) : ((double) 0f), (reader["TOTAL_CUBE"].ToString() != "") ? ((double) float.Parse(reader["TOTAL_CUBE"].ToString())) : ((double) 0f), (reader["TOTAL_PRICE"].ToString() != "") ? ((double) float.Parse(reader["TOTAL_PRICE"].ToString())) : ((double) 0f), reader["QC_AUTO_ADJUST"].ToString(), reader["QC_REQUIRED"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["REMARK"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["STATUS_D"].ToString());
                purchaseOrderDetailInfos.Add(purchaseOrderDetailInfo);
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return purchaseOrderDetailInfos;
        }

        public int InsertPurchaseOrderDetail(PurchaseOrderDetailInfo purchaseOrderDetailInfo, List<string> whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    purchaseOrderDetailInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_PurchaseOrderDetail_Parameters(purchaseOrderDetailInfo);
                    if (paras != null)
                    {
                        result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_PURCHASE_ORDER_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int InsertPurchaseOrderDetail(DataBase dataBase, DbTransaction tran, PurchaseOrderDetailInfo purchaseOrderDetailInfo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    purchaseOrderDetailInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_PurchaseOrderDetail_Parameters(purchaseOrderDetailInfo);
                    if (paras != null)
                    {
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_PURCHASE_ORDER_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int PurchaseOrderDetailPriceChanges(DataBase dataBase, DbTransaction tran, string poID, string poLineID, double price, string whLoginID, string updatedBy)
        {
            int result = 0;
            try
            {
                string sql = this.SQL_UPDATE_PURCHASE_ORDER_DETAIL_PRICE.Replace("@_@", whLoginID);
                SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@UNIT_PRICE", price), new SqlParameter("@UPDATED_BY", updatedBy), new SqlParameter("@PO_ID", poID), new SqlParameter("@LINE_ID", poLineID) };
                result = dataBase.ExecuteNonQuery(tran, CommandType.Text, sql, paras);
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        private SqlParameter[] Set_PurchaseOrderDetail_Parameters(PurchaseOrderDetailInfo purchaseOrderDetailInfo)
        {
            SqlParameter[] paramArray = new SqlParameter[] { 
                new SqlParameter(this.WH_ID, SqlDbType.VarChar, 30), new SqlParameter(this.PO_ID, SqlDbType.VarChar, 20), new SqlParameter(this.LINE_ID, SqlDbType.Int, 4), new SqlParameter(this.OWNER_ID, SqlDbType.VarChar, 20), new SqlParameter(this.EXTERNAL_PO_ID, SqlDbType.VarChar, 20), new SqlParameter(this.EXTERNAL_LINE_ID, SqlDbType.VarChar, 20), new SqlParameter(this.STATUS, SqlDbType.VarChar, 20), new SqlParameter(this.SKU_ID, SqlDbType.VarChar, 50), new SqlParameter(this.SKU_DESC, SqlDbType.VarChar, 100), new SqlParameter(this.ALT_SKU_ID, SqlDbType.VarChar, 50), new SqlParameter(this.ORDERED_QTY, SqlDbType.Decimal, 13), new SqlParameter(this.ADJUSTED_QTY, SqlDbType.Decimal, 13), new SqlParameter(this.RECEIVED_QTY, SqlDbType.Decimal, 13), new SqlParameter(this.REJECTED_QTY, SqlDbType.Decimal, 13), new SqlParameter(this.PACK_ID, SqlDbType.VarChar, 50), new SqlParameter(this.UNIT_PRICE, SqlDbType.Float, 8), 
                new SqlParameter(this.UOM_ID, SqlDbType.VarChar, 20), new SqlParameter(this.TOTAL_GROSS_WEIGHT, SqlDbType.Float, 8), new SqlParameter(this.TOTAL_NET_WEIGHT, SqlDbType.Float, 8), new SqlParameter(this.TOTAL_CUBE, SqlDbType.Float, 8), new SqlParameter(this.TOTAL_PRICE, SqlDbType.Float, 8), new SqlParameter(this.QC_AUTO_ADJUST, SqlDbType.VarChar, 1), new SqlParameter(this.QC_REQUIRED, SqlDbType.VarChar, 1), new SqlParameter(this.UDF1, SqlDbType.VarChar, 30), new SqlParameter(this.UDF2, SqlDbType.VarChar, 30), new SqlParameter(this.UDF3, SqlDbType.VarChar, 30), new SqlParameter(this.UDF4, SqlDbType.VarChar, 30), new SqlParameter(this.UDF5, SqlDbType.VarChar, 30), new SqlParameter(this.UDF6, SqlDbType.VarChar, 30), new SqlParameter(this.UDF7, SqlDbType.VarChar, 30), new SqlParameter(this.UDF8, SqlDbType.VarChar, 30), new SqlParameter(this.UDF9, SqlDbType.VarChar, 30), 
                new SqlParameter(this.UDF10, SqlDbType.VarChar, 30), new SqlParameter(this.REMARK, SqlDbType.VarChar, 0x3e8), new SqlParameter(this.CREATED_BY, SqlDbType.VarChar, 20), new SqlParameter(this.UPDATED_BY, SqlDbType.VarChar, 20)
             };
            if (!string.IsNullOrEmpty(purchaseOrderDetailInfo.WhID))
            {
                paramArray[0].Value = purchaseOrderDetailInfo.WhID;
            }
            else
            {
                paramArray[0].Value = DBNull.Value;
            }
            paramArray[1].Value = purchaseOrderDetailInfo.PoID;
            paramArray[2].Value = purchaseOrderDetailInfo.LineID;
            paramArray[3].Value = purchaseOrderDetailInfo.OwnerID;
            if (!string.IsNullOrEmpty(purchaseOrderDetailInfo.ExternalPoID))
            {
                paramArray[4].Value = purchaseOrderDetailInfo.ExternalPoID;
            }
            else
            {
                paramArray[4].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(purchaseOrderDetailInfo.ExternalLineID))
            {
                paramArray[5].Value = purchaseOrderDetailInfo.ExternalLineID;
            }
            else
            {
                paramArray[5].Value = DBNull.Value;
            }
            paramArray[6].Value = purchaseOrderDetailInfo.Status;
            if (!string.IsNullOrEmpty(purchaseOrderDetailInfo.SkuID))
            {
                paramArray[7].Value = purchaseOrderDetailInfo.SkuID;
            }
            else
            {
                paramArray[7].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(purchaseOrderDetailInfo.SkuDesc))
            {
                paramArray[8].Value = purchaseOrderDetailInfo.SkuDesc;
            }
            else
            {
                paramArray[8].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(purchaseOrderDetailInfo.AltSkuID))
            {
                paramArray[9].Value = purchaseOrderDetailInfo.AltSkuID;
            }
            else
            {
                paramArray[9].Value = DBNull.Value;
            }
            paramArray[10].Value = purchaseOrderDetailInfo.OrderedQty;
            paramArray[11].Value = purchaseOrderDetailInfo.AdjustedQty;
            paramArray[12].Value = purchaseOrderDetailInfo.ReceivedQty;
            paramArray[13].Value = purchaseOrderDetailInfo.RejectedQty;
            paramArray[14].Value = purchaseOrderDetailInfo.PackID;
            paramArray[15].Value = purchaseOrderDetailInfo.UnitPrice;
            if (!string.IsNullOrEmpty(purchaseOrderDetailInfo.UomID))
            {
                paramArray[0x10].Value = purchaseOrderDetailInfo.UomID;
            }
            else
            {
                paramArray[0x10].Value = DBNull.Value;
            }
            paramArray[0x11].Value = purchaseOrderDetailInfo.TotalGrossWeight;
            paramArray[0x12].Value = purchaseOrderDetailInfo.TotalNetWeight;
            paramArray[0x13].Value = purchaseOrderDetailInfo.TotalCube;
            paramArray[20].Value = purchaseOrderDetailInfo.TotalPrice;
            paramArray[0x15].Value = purchaseOrderDetailInfo.QcAutoAdjust;
            paramArray[0x16].Value = purchaseOrderDetailInfo.QcRequired;
            if (!string.IsNullOrEmpty(purchaseOrderDetailInfo.Udf1))
            {
                paramArray[0x17].Value = purchaseOrderDetailInfo.Udf1;
            }
            else
            {
                paramArray[0x17].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(purchaseOrderDetailInfo.Udf2))
            {
                paramArray[0x18].Value = purchaseOrderDetailInfo.Udf2;
            }
            else
            {
                paramArray[0x18].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(purchaseOrderDetailInfo.Udf3))
            {
                paramArray[0x19].Value = purchaseOrderDetailInfo.Udf3;
            }
            else
            {
                paramArray[0x19].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(purchaseOrderDetailInfo.Udf4))
            {
                paramArray[0x1a].Value = purchaseOrderDetailInfo.Udf4;
            }
            else
            {
                paramArray[0x1a].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(purchaseOrderDetailInfo.Udf5))
            {
                paramArray[0x1b].Value = purchaseOrderDetailInfo.Udf5;
            }
            else
            {
                paramArray[0x1b].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(purchaseOrderDetailInfo.Udf6))
            {
                paramArray[0x1c].Value = purchaseOrderDetailInfo.Udf6;
            }
            else
            {
                paramArray[0x1c].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(purchaseOrderDetailInfo.Udf7))
            {
                paramArray[0x1d].Value = purchaseOrderDetailInfo.Udf7;
            }
            else
            {
                paramArray[0x1d].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(purchaseOrderDetailInfo.Udf8))
            {
                paramArray[30].Value = purchaseOrderDetailInfo.Udf8;
            }
            else
            {
                paramArray[30].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(purchaseOrderDetailInfo.Udf9))
            {
                paramArray[0x1f].Value = purchaseOrderDetailInfo.Udf9;
            }
            else
            {
                paramArray[0x1f].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(purchaseOrderDetailInfo.Udf10))
            {
                paramArray[0x20].Value = purchaseOrderDetailInfo.Udf10;
            }
            else
            {
                paramArray[0x20].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(purchaseOrderDetailInfo.Remark))
            {
                paramArray[0x21].Value = purchaseOrderDetailInfo.Remark;
            }
            else
            {
                paramArray[0x21].Value = DBNull.Value;
            }
            paramArray[0x22].Value = purchaseOrderDetailInfo.CreatedBy;
            paramArray[0x23].Value = purchaseOrderDetailInfo.UpdatedBy;
            return paramArray;
        }

        public int UpdatePurchaseOrderDetail(PurchaseOrderDetailInfo purchaseOrderDetailInfo, List<string> whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    purchaseOrderDetailInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_PurchaseOrderDetail_Parameters(purchaseOrderDetailInfo);
                    if (paras != null)
                    {
                        result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_PURCHASE_ORDER_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int UpdatePurchaseOrderDetail(DataBase dataBase, DbTransaction tran, PurchaseOrderDetailInfo purchaseOrderDetailInfo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    purchaseOrderDetailInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_PurchaseOrderDetail_Parameters(purchaseOrderDetailInfo);
                    if (paras != null)
                    {
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_PURCHASE_ORDER_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int UpdatePurchaseOrderDetailStatus(string poID, string status, string whLoginID, string updatedBy)
        {
            int result = 0;
            try
            {
                string sql = this.SQL_UPDATE_PURCHASE_ORDER_DETAIL_STAUTS.Replace("@_@", whLoginID);
                SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@STATUS", status), new SqlParameter("@UPDATED_BY", updatedBy), new SqlParameter("@PO_ID", poID) };
                result = DBHelper.ExecuteNonQuery(CommandType.Text, sql, paras);
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int UpdatePurchaseOrderDetailStatus(DataBase dataBase, DbTransaction tran, string poID, string status, string whLoginID, string updatedBy)
        {
            int result = 0;
            try
            {
                string sql = this.SQL_UPDATE_PURCHASE_ORDER_DETAIL_STAUTS.Replace("@_@", whLoginID);
                SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@STATUS", status), new SqlParameter("@UPDATED_BY", updatedBy), new SqlParameter("@PO_ID", poID) };
                result = dataBase.ExecuteNonQuery(tran, CommandType.Text, sql, paras);
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }
    }
}

